package com.atguigu.gmall.sms.config;

import com.zaxxer.hikari.HikariDataSource;
import io.seata.rm.datasource.DataSourceProxy;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
 * @author liuxing
 * @create 2022-09-08 14:18
 */
@Configuration
public class DataSourceConfig {


    @Primary
    @Bean("dataSource")
    public DataSource dataSource(@Value("${spring.datasource.driver-class-name}") String driverClassName,
                                    @Value("${spring.datasource.url}") String url,
                                    @Value("${spring.datasource.password}") String password,
                                    @Value("${spring.datasource.username}") String username) {

        HikariDataSource hikari = new HikariDataSource();
        hikari.setDriverClassName(driverClassName);
        hikari.setJdbcUrl(url);
        hikari.setUsername(username);
        hikari.setPassword(password);

        return new DataSourceProxy(hikari);
    }

}
